/***
 * @file: Composition API替换mixins
 * @author: xiaoyu
 * @Date: 2021-07-08 10:17:32
 */

import { computed, onMounted, reactive, ref } from 'vue'
import httpService from '../../utils/axios/http'

export default function filterTest() {
  const filterStr = ref('')
  const dataList = reactive<Array<any>>([])

  const filterList = computed(() => {
    console.log('过滤啦...')
    return dataList.filter((item) => {
      return item.name.indexOf(filterStr.value) !== -1
    })
  })
  function getList() {
    const data = [
      {
        name: '张三',
        age: 24
      },
      {
        name: '李四',
        age: 44
      },
      {
        name: '王五',
        age: 56
      },
      {
        name: '赵六',
        age: 12
      },
      {
        name: '钱起',
        age: 67
      },
      {
        name: '孙久',
        age: 32
      }
    ]
    // 模拟异步请求获取数据
    setTimeout(() => {
      data.forEach((item) => {
        dataList.push(item)
      })
    })
  }
  onMounted(() => {
    getList()
  })
  return {
    filterStr,
    filterList
  }
}
